/*
 * @lc app=leetcode.cn id=206 lang=javascript
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
// 递归 讲链表前一项，当前项指向反转
 function reverse(prev, cur) {
    if (!cur) return prev;
    const tem = cur.next;
    cur.next = prev;
    return reverse(cur, tem);
}
var reverseList = function(head) {
  return reverse(null, head);
};
// @lc code=end

